package action.observer;

import java.util.ArrayList;
import java.util.List;

public class Displayer implements Observer{
    private String name;
    private float humidity;
    private float pressure;

    //保存注册的主题列表
    private final List<Subject> subjects=new ArrayList<>();

    public Displayer(String name) {
        this.name = name;
    }

    @Override
    public void update(float humidity, float pressure) {
        this.humidity=humidity;
        this.pressure=pressure;
        displayData();
    }

    public void displayData() {
        System.out.println(name+"湿度为"+humidity+"压力为"+pressure);
    }

    @Override
    public void registerToSubject(Subject subject) {
        subject.registerObserver(this);
        subjects.add(subject);
    }

    @Override
    public void removeFromSubject(Subject subject) {
        subject.removeObserver(this);
        subjects.remove(subject);
    }


}
